package viethp.mtrade.customactivities;

import java.util.ArrayList;

import viethp.mtrade.activities.AHaveGroupTitle;
import viethp.mtrade.activities.R;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

public class ATabHaveGroup extends ActivityGroup{
	public static ATabHaveGroup group;
	private static ArrayList<View> arrList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		arrList = new ArrayList<View>();
		group = this;

		View view = getLocalActivityManager().startActivity("ATabHaveTitle",	new Intent(this, AHaveGroupTitle.class)
						.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
				.getDecorView();
		
		replaceView(view);
	}

	public void replaceView(View view) {
		Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.slide_right_to_left_in);
	    view.startAnimation(hyperspaceJump);
		
		arrList.add(view);
		setContentView(view);
	}

	public void back() {
		if(arrList.size() > 1){
			arrList.remove(arrList.size() - 1);
			View v = arrList.get(arrList.size() - 1);
			Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.slide_left_to_right_in);
		    v.startAnimation(hyperspaceJump);
			setContentView(v);
		}else{
			this.finish();
		}
	}

	@Override
	public void onBackPressed() {
		ATabHaveGroup.group.back();
	}
}
